"""
控制端主程序: 用于发送控制脚本
"""
from include.device import *
from threading import Thread


masterList = []


def mainInterface():
    print(
        """
    主控制台:
    1. 查看连接设备
    2. 连接新设备
    3. 控制设备
    """
    )
    ch = input("choice: ")
    return ch


def checkandcreate():
    num = 0
    while True:
        try:
            globals()["master" + str(num)]
            num += 1
        except:
            globals()["master" + str(num)] = master(name="master" + str(num))
            masterList.append(globals()["master" + str(num)])
            break


while True:

    ch = int(mainInterface())

    if ch == 1:
        for i in masterList:
            print(i.dolls)
        print('----------------')
        continue

    if ch == 2:
        checkandcreate()
        for ma in masterList:
            if ma.inuse == True:
                continue
            else:
                tempMa = ma
                break
        target = input()
        tempMa.connect(target=target)
        continue

    if ch == 3:
        ind = int(input("hostID:"))
        tempMa = masterList[ind - 1]
        tempMa.control()
        continue
